package com.agu.common.page;

import java.io.Serializable;
import java.util.Map;

public class PageVo implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7289925623459534820L;

	/**
	 * 是否本地翻页
	 */
	private boolean local;
	/**
	 * 页码
	 */
	private int page = 1;
	/**
	 * 页面大小
	 */
	private int pageSize = 10;

	/**
	 * 总条数
	 */
	private int total;

	public PageVo() {
		super();
	}

	public PageVo(int page, int pageSize) {
		super();
		this.page = page;
		this.pageSize = pageSize;
	}

	public boolean isLocal() {
		return local;
	}

	public void setLocal(boolean local) {
		this.local = local;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public void setTotal(long total) {
		this.total = (int) total;
	}

	public void setCurrentPage(int currentPage) {
		this.page = currentPage;
	}

	public int getStartRecord() {
		if (page < 1) {
			page = 1;
		}
		return pageSize * (page - 1);
	}

	/**
	 * 设置currentPage和pageSize
	 * 
	 * @param map
	 *            (currentPage,pageSize)
	 * @param pageKey
	 * @param pageSizeKey
	 */
	public void setMap(Map<String, Object> map, String pageKey, String pageSizeKey) {
		Object page = map.get(pageKey);
		Object pageSize = map.get(pageSizeKey);
		if (page != null) {
			int pages = Integer.parseInt(page.toString());
			if (pages > 0) {
				this.page = pages;
			}
		}
		if (pageSize != null) {
			int pageSizes = Integer.parseInt(pageSize.toString());
			if (pageSizes > 0) {
				this.pageSize = pageSizes;
			}
		}
	}

}
